import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;

public class Test {
    public static void main(String[] args) {
        //锁1
        Object locker1 = new Object();
        //锁2
        Object locker2 = new Object();

        Thread thread1 = new Thread(() -> {
            synchronized (locker1) {
                System.out.println("上了locker1锁");
            }
            synchronized (locker2) {
                System.out.println("上了locker2锁");
            }
        });

        Thread thread2 = new Thread(() -> {
            synchronized (locker2) {
                System.out.println("上了locker2锁");
            }
            synchronized (locker1) {
                System.out.println("上了locker1锁");
            }
        });

        thread1.start();
        thread2.start();

    }
    public static void main1(String[] args) throws InterruptedException {
        //锁
        Object locker =new Object();
        BlockingQueue<Integer> blockingQueue=new LinkedBlockingQueue<Integer>();

        Thread thread=new Thread(()->{
            synchronized (locker){
                try {
                    blockingQueue.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        Thread.sleep(1000);

        synchronized (locker){
            blockingQueue.put(1);
        }

    }
    public static void main2(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch=new CountDownLatch(5);
        System.out.println("开始比赛");
        for (int i = 0; i < 5; i++) {
          Thread thread=new Thread(){
              @Override
              public void run() {
                  System.out.println("到达终点");
                  countDownLatch.countDown();
              }
          };
          thread.start();

        };
        countDownLatch.await();
        System.out.println("结束");
    }
    public static void main3(String[] args) throws InterruptedException {
        Semaphore semaphore=new Semaphore(2);
        semaphore.acquire();
        semaphore.acquire();
        semaphore.release();
        semaphore.release();
    }
}
